package cn.zhonghuanzhiyuan.sprc.basicinfo.controller;

import cn.org.bachelor.web.json.JsonResponse;
import cn.zhonghuanzhiyuan.sprc.basicinfo.domain.Demo;
import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.AddDemoVo;
import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.QueryDemoVo;
import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.UpdateDemoVo;
import cn.zhonghuanzhiyuan.sprc.basicinfo.service.DemoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: eprs
 * @BelongsPackage: cn.zhonghuanzhiyuan.eprs.command.controller
 * @Author: Hyw
 * @CreateTime: 2024-01-08  14:38
 * @Description: demo
 * @Version: 1.0
 */
@Api(tags = "xxx-xxx")
@RestController
@RequestMapping("/demo")
@CrossOrigin // 线上不需要 （要注掉）
public class DemoController {

    @Autowired
    private DemoService demoService;

    @ApiOperation(value = "新增xxx")
    @PostMapping("/saveDemo")
    public HttpEntity<JsonResponse> saveDemo(@ApiParam(name = "AddDemoVo", value = "新增Demo对象", required = true) @RequestBody AddDemoVo vo) {
        demoService.saveDemo(vo);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "批量删除根据ID")
    @DeleteMapping("/deleteDemoByIds/{ids}")
    public HttpEntity<JsonResponse> deleteDemoByIds(@ApiParam(name = "idList", value = "主键集合", required = true) @PathVariable String ids) {
        demoService.deleteDemoByIds(ids);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "修改xxx")
    @PutMapping("/updateDemo")
    public HttpEntity<JsonResponse> updateDemo(@ApiParam(name = "UpdateDemoVo", value = "修改Demo对象", required = true) @RequestBody UpdateDemoVo vo) {
        demoService.updateDemo(vo);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "获取分页列表")
    @PostMapping("getDemoList")
    public HttpEntity<JsonResponse> getDemoList(@ApiParam(name = "demoQueryVo", value = "查询对象", required = true) @RequestBody QueryDemoVo demoQueryVo) {
        PageHelper.startPage(demoQueryVo.getPageNum(), demoQueryVo.getPageSize());
        List<Demo> list = demoService.selectDemoPage(demoQueryVo);
        return JsonResponse.createHttpEntity(new PageInfo<>(list), HttpStatus.OK);
    }

    @ApiOperation(value = "获取详情xxx")
    @GetMapping("/getDemoById/{id}")
    public HttpEntity<JsonResponse> getDemoById(@ApiParam(name = "id", value = "主键", required = true) @PathVariable String id) {
        return JsonResponse.createHttpEntity(demoService.getDemoById(id), HttpStatus.OK);
    }
}
